package org.jsbd.boss.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.common.ResponseMapUtils;
import org.jsbd.boss.domian.UserUpgradeVo;
import org.jsbd.boss.domian.statistics.AddStatisticsVo;
import org.jsbd.boss.service.IUserUpgradeService;
import org.jsbd.boss.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 用户升级查询
 * @author lhz
 * @date:   2018年8月29日 下午3:33:22
 */
@Controller
@RequestMapping("/user/upgrade")
public class UserUpgradeController {
	public static final Logger LOGGER = LoggerFactory.getLogger(UserUpgradeController.class);
	@Autowired
	private IUserUpgradeService userUpgradeService;
	
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String configList(Model model) {
		return "upgrade/index";
	}
	
	/**
	 * 列表
	 * @param page
	 * @param douyingAddConfig
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "unUpgrageList")
	@ResponseBody
	public Map<String, Object> unUpgrageList(DataGridModel page,  UserUpgradeVo userUpgradeVo) throws Exception {
		if (StringUtils.isBlank(userUpgradeVo.getMark()) && StringUtils.isBlank(userUpgradeVo.getName())) {
			return new HashMap<>();
		}
		userUpgradeVo.setPageInfo(page);
		return userUpgradeService.getUnUpgrageList(userUpgradeVo);
	}
	
	/**
	 * 校准根据mark
	 * @param correcStart
	 * @param endStart
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/calByMark")
	public Map<String,Object> calByMark(String mark) throws Exception {
		if (StringUtils.isBlank(mark)) {
			return ResponseMapUtils.responseFail("请输入mark");
		}
		userUpgradeService.updateJZByMark(mark);
		return ResponseMapUtils.responseSuccess();
	}
	
	/**
	 * 校准更具rd
	 * @param startTime
	 * @param endTime
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/calByRd")
	public Map<String,Object> calByRd(String startTime, String endTime, String mark) throws Exception {
		if (StringUtils.isBlank(startTime)) {
			return ResponseMapUtils.responseFail("请输入起始日期");
		}
		if (StringUtils.isBlank(endTime)) {
			endTime = DateUtil.getY_M_DStr();
		}
		userUpgradeService.updateJZByRd(startTime, endTime, mark);
		return ResponseMapUtils.responseSuccess();
	}
	
	/**
	 * 新增校准页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/addJZIndex", method = RequestMethod.GET)
	public String addJZIndex(Model model) {
		return "upgrade/addJZIndex";
	}
	
	/**
	 * 列表
	 * @param page
	 * @param userUpgradeVo
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "addJZList")
	@ResponseBody
	public Map<String, Object> addJZList(DataGridModel page,  AddStatisticsVo addStatisticsVo) throws Exception {
		if (StringUtils.isBlank(addStatisticsVo.getMark()) && StringUtils.isBlank(addStatisticsVo.getName())) {
			return new HashMap<>();
		}
		addStatisticsVo.setPageInfo(page);
		return userUpgradeService.getAddJZList(addStatisticsVo);
	}
	
	/**
	 * 新增执行校准
	 * @param startTime
	 * @param endTime
	 * @param mark
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("/addJZByDate")
	public Map<String,Object> addJZByDate(String startTime, String endTime, String mark) throws Exception {
		if (StringUtils.isBlank(startTime)) {
			return ResponseMapUtils.responseFail("请输入起始日期");
		}
		if (StringUtils.isBlank(endTime)) {
			endTime = DateUtil.getY_M_DStr();
		}
		userUpgradeService.updateAddJZByDate(startTime, endTime, mark);
		return ResponseMapUtils.responseSuccess();
	}
	
}
